﻿using System.Collections.Generic;
using System.Collections.ObjectModel;
using Core;
using Core.CSV;
using Core.Event;
using Core.Log;
using Unity.VisualScripting;

namespace Game {
    public partial class Weapon {
        /// <summary>
        /// 替换效果
        /// </summary>
        public void InsertEffect(WeaponEffect effect, int index) {
            if (!mEffects.IsActive(index)) {
                return;
            }
            mEffects[index]?.Detach();
            effect.Init(this, mEffects, index);
            mEffects[index] = effect;
            effect.Attach();
            
            GameEventMgr.Ins.PushEvent(GameEventID.WeaponEdit);
            ADbg.LogF("[WeaponEffect] 武器效果ID：{0}，附加在武器：{1}",effect.Data.ID,Data.Name);
        }

        /// <summary>
        /// 替换效果
        /// </summary>
        public void InsertEffect(int index1, int index2) {
            if (!mEffects.IsActive(index1) || !mEffects.IsActive(index2)) {
                return;
            }

            mEffects[index1].Init(this,mEffects,index2);
            mEffects[index2].Init(this,mEffects,index1);
            mEffects[index2].Detach();
            mEffects[index1].Detach();
            mEffects[index1].Attach();
            mEffects[index1].Attach();
            
            GameEventMgr.Ins.PushEvent(GameEventID.WeaponEdit);
        }
        
        /// <summary>
        /// 移除效果
        /// </summary>
        public void RemoveEffect(int index) {
            if (!mEffects.IsActive(index)) {
                return;
            }
            mEffects[index]?.Detach();
            mEffects[index] = default;
            GameEventMgr.Ins.PushEvent(GameEventID.WeaponEdit);
        }


        public ReadOnlyCollection<WeaponEffect> GetWeaponEffectList() {
            return mEffects.AsReadOnly();
        }
    }
}